#include "pch.h"
#include "Server.h"

using namespace std;
Server::Server()
{
}

void Server::initialize(Application& self)
{
    Application::initialize(self);

    mk_config config = { 0 };
    config.log_mask = LOG_CONSOLE | LOG_FILE;
    config.log_level = 0;
    mk_env_init(&config);
    mk_set_log(4, 10);
    rtspMedia = std::make_shared<RtspMedia>();
}

void Server::uninitialize()
{
    rtspMedia->StopPush();
    rtspMedia->StopCapture();
    mk_stop_all_server();
    Application::uninitialize();
}

int Server::main(const std::vector<std::string>& args)
{
    while (true)
    {
        int port = mk_rtsp_server_start(554, 0);
        if (port == 0) {
            std::this_thread::sleep_for(1000ms);
        }
        else
        {
            break;
        }
    }
    rtspMedia->StartCapture();
    rtspMedia->StartPush();
    waitForTerminationRequest();
    return 0;
}


